﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />

<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>工艺路线编辑</title>
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            编号
                        </div>
                        <div style="left:28px">
                            <input type="text" name="RouteNo" value="" lay-verify="required" placeholder="请输入编号" lay-reqtext="请填写编号" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                        <div class="layui-input-prefix" style="left:40px">
                            名称
                        </div>
                        <div style="left:40px">
                            <input type="text" name="RouteName" value="" lay-verify="required" placeholder="请输入名称" lay-reqtext="请填写名称" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                        <div class="layui-input-prefix" style="left:50px">
                            是否启用
                        </div>
                        <div style="width:300px;left:50px">
                            <input type="radio" name="IsNo" value="1" title="是" lay-filter="demo-radio-filter" checked>
                            <input type="radio" name="IsNo" value="0" lay-filter="demo-radio-filter" title="否">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            说明
                        </div>
                        <div style="left:28px">
                            <textarea style="width:700px" type="textarea" name="RouteExplain" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写说明" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            备注
                        </div>
                        <div style="left:28px">
                            <textarea style="width:700px" type="textarea" name="Comment" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
    </form>

</body>

</html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <div class="layui-tab" lay-filter="test-hash">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="11">组成工序</li>
            <li lay-id="22">关联产品</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <div class="layui-form">
                    <div class="layui-row layui-col-space16">
                        <div class="layui-col-md4">
                            <div class="layui-input-wrap">
                                <div class="layui-input-group">
                                    <div class="layui-input-split layui-input-prefix">
                                        工序编号
                                    </div>
                                    <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="ProcedureCode" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-input-wrap">
                                <div class="layui-input-group">
                                    <div class="layui-input-split layui-input-prefix">
                                        工序名称
                                    </div>
                                    <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="ProcessName">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-input-wrap">
                                <div class="layui-input-group">
                                    <div class="layui-input-split layui-input-prefix">
                                        是否启用
                                    </div>
                                    <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="isEnable">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-input-wrap">
                                <div class="layui-input-group">
                                    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="StashHtml()">查询</button>
                                    <div>
                                        <button type="button" class="layui-btn layui-bg-red" lay-on="test-iframe-curl">新增</button>
                                        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div>

                    <table class="layui-hide" id="ID-table-demo-data"></table>
                </div>
                <script type="text/html" id="toolDemo">
                    <div class="layui-clear-space">
                      <a onclick="Update()" lay-on="test-iframe-curs"  style="color:cornflowerblue">编辑</a>

                    </div>
                </script>

            </div>

            <div class="layui-tab-item">

                <form class="layui-form" action="">

        <div class="layui-form">
            <div class="layui-row layui-col-space16">

                <div class="layui-col-md4">
                    <div class="layui-input-wrap">

                        <div class="layui-input-group">
                            <div class="layui-input-split layui-input-prefix">
                                物料编码
                            </div>
                            <input type="text" id="productManageNodes" autocomplete="off" placeholder="请输入物料编码" lay-affix="clear" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-input-wrap">

                        <div class="layui-input-group">
                            <div class="layui-input-split layui-input-prefix">
                                物料名称
                            </div>
                            <input type="text" id="productManageNames" autocomplete="off" placeholder="请输入物料名称" lay-affix="clear" class="layui-input">
                        </div>
                    </div>
                </div>
                <!-- 按钮 -->


                <div class="layui-btn-container">
                    <button class="layui-btn" id="searchBtn" lay-submit lay-filter="demo2">搜索</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    @*  <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-custom" lay-event="detail">
                    <span class="layui-badge-dot"></span> 新增
                    </button> *@
                </div>

                <div class="layui-btn-container">
                    <button type="button" class="layui-btn layui-btn-primary" lay-event="detail" lay-on="test-page-custom" >
                        <span class="layui-badge-dot"></span> 新增
                    </button>
                </div>

            </div>
                       
        </div>
                    
    </form>
   @*    <div style="float:right;margin-right:20px;">
          <!-- 表格 -->
          <table class="layui-table">
              <colgroup>
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col width="130">
                  <col>
              </colgroup>
              <thead>
                  <tr>
                      <th><input type="checkbox" name="select-all" lay-filter="select-all"/></th>
                      <th>物料编码</th>
                      <th>物料名称</th>
                      <th>规格型号</th>
                      <th>单位</th>
                      <th>物料/产品</th>
                      <th>所属分类</th>
                      <th>是否启用</th>
                      <th>设置安全库存</th>
                      <th>操作</th>
                  </tr>
              </thead>
              <tbody id="productManageTable">
              </tbody>
          </table>
          <div id="demo-laypage-all"></div>
      </div> *@


     
                <div>

                    <table class="layui-hide" id="ID-table-demo-datas"></table>
                </div>


            </div>

        </div>
        <div class="layui-form-item" style="width: 100px;left:700px">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-loginS">确定</button>
        </div>
    </div>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
    <script>
        layui.use(function () {
            var element = layui.element;

            // hash 地址定位
            var hashName = 'tabid'; // hash 名称
            var layid = location.hash.replace(new RegExp('^#' + hashName + '='), ''); // 获取 lay-id 值

            // 初始切换
            element.tabChange('test-hash', layid);
            // 切换事件
            element.on('tab(test-hash)', function (obj) {
                location.hash = hashName + '=' + this.getAttribute('lay-id');
            });
        });
    </script>

</body>
</html>
<script>
    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form;
        var $ = layui.$;
        var table = layui.table
        var layer = layui.layer;
        var util = layui.util;
        var laydate = layui.laydate;
        var laypage = layui.laypage;
        var pageIndex = 1;
        var pageSize = 2;
        $(() => {

            CraftRouteBack();

            StashHtml()
            StashHtmls()
        })

        // Show(pageIndex, pageSize);

        //仓库显示
        function StashHtmls() {

            $.ajax({
                url: '@ViewBag.FoundationWrite' + '/api/ProductType/ProductManagesLists',
                data: JSON.stringify({
                    pageIndex: 1,
                    pageSize: 10,
                    productManageNodes: $("#productManageNodes").val(),
                    productManageNames: $("#productManageNames").val(),
                }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                  
                    console.log(res.data,'77')
                    layui.use('table', function () {
                        var table = layui.table;

                        // 已知数据渲染
                        var inst = table.render({
                            elem: '#ID-table-demo-datas',
                            cols: [[ //标题栏
                                { type: 'checkbox', title: '复选框', fixed: true }, // 单选框
                                { field: 'productManageNode', title: '物料编码', width: 200, sort: true },
                                { field: 'productManageName', title: '物料名称', width: 200 },
                                { field: 'productManageNumber', title: '规格型号', width: 200 },
                                { field: 'unites', title: '单位', width: 200 },
                                { field: 'productZoo', title: '物料', width: 200 },
                                { field: 'productTypeId', title: '所属分类', width: 200 },
                                { field: 'isNo', title: '是否启用', width: 200, sort: true },
                                { field: 'inventory', title: '设置安全库存', width: 200, sort: true },
                                { fixed: 'right', title: '操作', width: 134, minWidth: 125, templet: '#toolDemo' }
                            ]],
                            toolbar: '#toolbarDemo',
                            data: res.data,
                            //skin: 'line', // 表格风格
                            //even: true,
                            page: true, // 是否显示分页
                            limits: [5, 10, 15],
                            limit: 5 // 每页默认显示的数量
                        });
                    });
                }

            })
        }

        var newid = "";
        // 触发表格复选框选择
        table.on('checkbox(ID-table-demo-datas)', function (obj) {
            newid = obj.data.productManageId
            console.log(newid, '8888');
        });



        //显示
        // function Show(index, size) {
        //     $.post({
        //         url: '@ViewBag.FoundationWrite' + '/api/ProductType/ProductManagesLists',
        //         data: JSON.stringify
        //             ({
        //                 pageIndex: index,
        //                 pageSize: size,
        //                 productManageNodes: $("#productManageNodes").val(),
        //                 productManageNames: $("#productManageNames").val(),
        //             }),
        //         async: false,
        //         dataType: "json",
        //         contentType: "application/json",
        //         success: res => {
        //             var count = "";

        //             // var aa = moment(this.dieDate).format("YYYY-MM-DD HH:mm:ss")
        //             // var bb = this.dieReason == 1 ? "腹泻" : this.dieReason == 2 ? "肺炎" : this.dieReason == 3 ? "发热" : "猝死";
        //             // var cc = this.sheepSex == 0 ? "公" : "母";
        //             var dd = moment(this.productManageTime).format("YYYY-MM-DD HH:mm:ss")
        //             console.log("!!!!!!!",res)
        //             $.each(res.data, function () {
        //                 count += `<tr>
        //                               <td><input type="checkbox" name="select-all" lay-filter="select-all" onclick="GetClient(${this.ProductManageId},'${this.productManageNode}','${this.productManageName}')"></input></td>
        //                           <td>${this.productManageNode}</td>
        //                           <td>${this.productManageName}</td>
        //                           <td>${this.productManageNumber}</td>
        //                           <td>${this.unites}</td>
        //                           <td>${this.productZoo}</td>
        //                           <td>${this.productTypeId}</td>
        //                           <td>${this.isNo}</td>
        //                           <td>${this.inventory}</td>
        //                           <td><a onclick="GetClientss(${this.ProductManageId},'${this.productManageNode}','${this.productManageName}','${this.productManageNumber}','${this.unites}','${this.productZoo}','${this.productTypeId}','${this.isNo}','${this.inventory}')" class="btn btn-link">选择</a></td>
        //                             </tr>
        //                             `
        //             })
        //             //pagedCount = res.pagedCount;
        //             //pcount = res.totalCount;
        //             $("#productManageTable").html(count)
        //             // console.log(res.data)

        //             //var page = Math.ceil(res.totalCount / 5);  //总页数
        //             console.log(996, pageSize, pageIndex, res);
        //             // 完整显示
        //             laypage.render({
        //                 elem: 'demo-laypage-all', // 元素 id
        //                 count: res.totalCount, // 数据总数
        //                 curr: index,//当前页
        //                 limit: size,//每页几条
        //                 limits: [1, 2, 3],
        //                 layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
        //                 jump: function (obj, first) {
        //                     if (!first) {
        //                         Show(obj.curr, obj.limit);
        //                     }
        //                 }
        //             });
        //         }
        //     })
        // }

        // function GetClient(ProductManageId, productManageNode, productManageName, productManageNumber, unites, productZoo, productTypeId, isNo, inventory) {
        //     localStorage.setItem("ProductManageId", ProductManageId);
        //     $("[name='productManageNode']").val(productManageNode);
        //     $("[name='productManageName']").val(productManageName);
        //     $("[name='productManageNumber']").val(productManageName);
        //     $("[name='unites']").val(productManageName);
        //     $("[name='productZoo']").val(productManageName);
        //     $("[name='productTypeId']").val(productManageName);
        //     $("[name='isNo']").val(productManageName);
        //     $("[name='inventory']").val(productManageName);
        //     layer.close(layer.index); // 关闭弹层
        //     form.render(); // 重新渲染
        // }

        //仓库显示
        function StashHtml() {


            var ProcedureCode = $("#ProcedureCode").val();
            var ProcessName = $("#ProcessName").val();
            var isEnable = "";
            var gh = $("#isEnable").val();
            if (gh == "") {
                isEnable = 0;
            }
            else {
                isEnable = $("#isEnable").val();
            }


            $.ajax({

                url: '@ViewBag.FoundationRead' + "/api/Acquire/processhtml",
                data: JSON.stringify({ ProcedureCode: ProcedureCode, ProcessName: ProcessName, isEnable: isEnable }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {

                    console.log(res.data)
                    layui.use('table', function () {
                        var table = layui.table;

                        // 已知数据渲染
                        var inst = table.render({
                            elem: '#ID-table-demo-data',
                            toolbar: '#toolbarDemo',
                            cols: [[ //标题栏
                                { type: 'checkbox', title: '复选框', fixed: true }, // 单选框
                                { field: 'procedureCode', title: '工序编码', width: 200 },
                                { field: 'processName', title: '工序名称', width: 200 },
                                { field: 'isEnable', title: '是否启用', width: 200 },
                                { field: 'processInstructions', title: '备注', width: 200 },
                                { fixed: 'right', title: '操作', width: 134, minWidth: 125, templet: '#toolDemo' }
                            ]],
                            data: res.data,
                            //skin: 'line', // 表格风格
                            //even: true,
                            page: true, // 是否显示分页
                            limits: [5, 10, 15],
                            limit: 5 // 每页默认显示的数量
                        });
                    });
                }

            })
        }

        // 事件
        util.on('lay-on', {

            'test-iframe-curl': function () {
                layer.open({
                    type: 2,
                    title: '增加工序',
                    shadeClose: true,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['900px', '600px'],
                    content: '/Document/ProcessAdds'
                });
            }
        })

        var getid = 0;

        // 触发表格复选框选择
        table.on('checkbox(ID-table-demo-data)', function (obj) {
            getid = obj.data.processid
        });


        var $ = layui.$;
        var table = layui.table
        var layer = layui.layer;
        var util = layui.util;
        function Update() {

            
            // 事件
            util.on('lay-on', {

                'test-iframe-curs': function () {
                    layer.open({
                        type: 2,
                        title: '工序编辑',
                        shadeClose: true,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['900px', '600px'],
                        content: '/Document/Processback?id=' + getid
                    });
                }
            })

        }



        var hk = "";
        function CraftRouteBack() {


            var routeId = location.href.split("=")[1];
            hk = routeId;
         
            $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/Jocker/CraftRouteBack",
                type: "post",
                data: JSON.stringify({ RouteId: routeId }),
                dataType: "json",
                async: false,
                contentType: "application/json",
                success: res => {
                    console.log(res.data)

                    $("[name='RouteNo']").val(res.data[0].routeNo);
                    $("[name='RouteName']").val(res.data[0].routeName);
                    $("[name='RouteExplain']").val(res.data[0].routeExplain);
                    $("[name='IsNo']").val(res.data[0].isNo);
                    $("[name='Comment']").val(res.data[0].comment);
               
                    form.render();
                }

            })

        }
        form.on('submit(demo-loginS)', function(data){
            let date = {
                routeId: hk,
                routeNo: $("[name='RouteNo']").val(),
                routeName: $("[name='RouteName']").val(),
                routeExplain: $("[name='RouteExplain']").val(),
                isNo: $("[name='IsNo']").val(),
                comment: $("[name='Comment']").val(),
            };

            console.log(date, '111111111')
            //url: '@ViewBag.FoundationWrite ' + "/api/Jocker/CraftRouteUpdate",
            $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/Jocker/CraftRouteUpdate",
                type: "post",
                data: JSON.stringify(date),
                dataType: "json",
                async: false,
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    if (res.code == 1) {
                        layer.msg("修改成功", { icon: 1, time: 1000 }, function () {
                            // 获得frame索                            
                        });
                    } else {
                        layer.msg(res.msg, { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });

   })
  
</script>
